package com.chenchao.thread;

import java.sql.Date;
import java.text.SimpleDateFormat;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/17 19:09
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.javathread.Test10.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * sleep模拟倒计时
 */
public class Test10 implements Runnable{
    public static void main(String[] args) {
        //Thread thread = new Thread(new Test10());
        //thread.start();
        time();


    }
    /**
     * 系统时间数10秒
     */
    public static void time(){
        Date date = new Date(System.currentTimeMillis());
        int i=10;
        while (i>0){
            System.out.println(new SimpleDateFormat("HH:mm:ss").format(date));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            date=new Date(System.currentTimeMillis());
            i--;
        }
    }

    /**
     * 10秒倒计时
     */
    @Override
    public void run() {
        int i=10;
        while (i>0){
            System.out.println(i--);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("点火");
    }
}
